
trait A {
    fn print(&self);
}
trait B {
    fn print(&self);
}

struct MyType;

impl A for MyType {
    fn print(&self) {
        println!("I am A MyType");
    }
}
impl B for MyType {
    fn print(&self) {
        println!("I am B MyType");
    }
}

impl MyType {
    fn print(&self) {
        println!("I am MyType");
    }
}

// 定义没有self的
trait Animal {
    fn baby_name() -> String;
}
struct Dog;
impl Dog {
    fn baby_name() -> String {
        String::from("Spot")
    }
}

impl Animal for Dog {
    fn baby_name() -> String {
        String::from("puppy")
    }
}

fn main() {
    // 同名方法的调用
    let my = MyType;
    my.print();  // 等价于MyType::print(&my);
    A::print(&my);
    B::print(&my);

    println!("baby_name: {}", Dog::baby_name());
    println!("{}", <Dog as Animal>::baby_name()); // 这里就叫完全限定语法
    // 完全限定语法的定义
    // <type as Trait>::function(.....)
    println!("Hello, world!");
}
